package com.leetcode.offer.chapter3;

/**
 * @author Dennis Li
 * @date 2020/7/13 11:07
 */
public class ExchangeOddAndEven_21 {

    // 首尾双指针
    public int[] exchange(int[] nums) {
        int len = nums.length;
        int[] aux = new int[len];
        int m = 0, n = len - 1;
        for (int i = 0, j = len - 1; i < len && j >= 0; i++, j--) {
            if((nums[i] & 1) == 1) aux[m++] = nums[i];
            if((nums[j] & 1) != 1) aux[n--] = nums[j];
        }
        return aux;
    }

}
